<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$this->pageTitle = 'Role Access'
?>
<div class="span10">
    <h1 class="page-header">Role Access</h1>
    <?php if (Yii::app()->user->hasFlash('error')): ?>
        <div class="alert alert-error fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <?php echo Yii::app()->user->getFlash('error') ?>
        </div>
    <?php endif; ?>
    <?php if (Yii::app()->user->hasFlash('success')): ?>
        <div class="alert alert-success fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <?php echo Yii::app()->user->getFlash('success') ?>
        </div>
    <?php endif; ?>
    <div>
        <form method="POST">
            <table class="table table-bordered">
                <tr>
                    <th>Controller</th>
                    <th>Action</th>
                    <?php foreach ($roles as $role) : ?>
                        <th><?php echo $role; ?></th>
                    <?php endforeach; ?>
                </tr>
                <?php
                foreach ($rules as $controller => $actions) :
                    if (count($actions) > 0):
                        $is_begin = TRUE;
                        ?>
                        <tr>
                            <td style="vertical-align: middle" rowspan="<?php echo count($actions); ?>"><?php echo str_replace('controller', '', $controller); ?></td>
                            <?php
                            foreach ($actions as $action => $value) :
                                if ($is_begin):
                                    $is_begin = FALSE;
                                    ?>
                                    <td><?php echo $action; ?></td>
                                    <?php foreach ($roles as $role) : ?>
                                        <td>
                                            <input type="checkbox" name="<?php echo "Resource[{$controller}][{$action}][]" ?>" value="<?php echo $role; ?>" <?php if(in_array($role, $value)){ echo "checked";}?>/>
                                        </td>
                                    <?php endforeach; ?>
                                    <?php
                                else:
                                    ?>
                                <tr>
                                    <td><?php echo $action; ?></td>
                                    <?php foreach ($roles as $role) : ?>
                                        <td>
                                            <input type="checkbox" name="<?php echo "Resource[{$controller}][{$action}][]" ?>" value="<?php echo $role; ?>" <?php if(in_array($role, $value)){ echo "checked";}?>/>
                                        </td>
                                    <?php endforeach; ?>
                                </tr>
                            <?php
                            endif;
                            ?>
                        <?php endforeach; ?>
                        </tr>
                        <?php
                    endif;
                endforeach;
                ?>
            </table>
            <div class="form-actions">
                <button id="save-category" type="submit" class="btn btn-primary">Lưu</button>
            </div>
        </form>
    </div>
</div>
